<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Session;

class CheckBrowser
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $path = $request->path();
        //微信：
//        if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
//            //微信端
//           //未认证：跳转到注册页面
//           /* Session::put('manager.id',Session::get('manager.id'));
//            Session::put('manager.name',Session::get('manager.name'));
//            Session::put('manager.phone',Session::get('manager.phone'));*/
//            Session::put('manager.perfix','wx');
//            Session::save();
////            $request->merge(['perfix'=>'wx']);
///*            if(!Session::get('manager.id')){
//                return redirect(url('wx/register'));
//            }*/
////            dd('check1');
//            if(strpos($path,'wap')!==false){
//                return redirect(url('wap/login'));
//            }
//        } else {
            //wap端
            //未登录：跳转到登录页面
            Session::put('manager.perfix','wap');
            Session::save();
//            $request->merge(['perfix'=>'wap']);
/*            if(!Session::get('manager.id')){
                return redirect(url('wap/login'));
            }*/
//            dd('check2');
//        }
        return $next($request);
    }
}
